package com.briup.cms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.domain.Category;
import com.briup.cms.domain.vo.CategoryVo;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-03-09
 */
@Api("栏目模块")
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    @ApiOperation("新增或修改栏目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "category",value = "新增或修改的栏目")
    })
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Category category){
        categoryService.saveOrUpdate(category);
        return Result.success();
    }

    @ApiOperation("删除栏目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "删除栏目id")
    })
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        categoryService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("查询栏目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
    })
    @GetMapping("/queryAll")
    public Result queryAll(int pageNum,int pageSize){
        IPage<Category> categoryIPage = categoryService.queryAll(pageNum, pageSize);
        return Result.success(categoryIPage);
    }

    @ApiOperation("查询一级栏目（含二级）")
    @GetMapping("/query")
    public Result query(){
        List<CategoryVo> categoryVos = categoryService.getCategoryVos();
        return Result.success(categoryVos);
    }
}

